package ai.people.netmon.framework.domain.archives.entity;

import ai.people.netmon.framework.domain.archives.vo.GangGroupInfoVO;
import ai.people.netmon.utils.StringPool;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 团伙基本信息
 * </p>
 *
 * @author zhenglin
 * @since 2022-06-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName(schema = "webservice", value = "gang_group_info")
@NoArgsConstructor
public class GangGroupInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @TableId
    private Long id;

    /**
     * 团伙名称
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupName;

    /**
     * 团伙照片
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupPicture;

    /**
     * 活动地区
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String activeRegion;

    /**
     * 团伙人数
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupPeopleCount;

    /**
     * 危险程度
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Integer degreeOfDanger;

    /**
     * 标签
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String tags;

    /**
     * 团伙创建者
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupCreator;

    /**
     * 现任首领
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupChief;

    /**
     * 团伙成立时间
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupCreateTime;

    /**
     * 团伙总部
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupHeadquarters;

    /**
     * 团伙信仰
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupFaith;

    /**
     * 团伙账号信息
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupSocial;

    /**
     * 团伙简介
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupBrief;

    /**
     * 团伙目标
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String groupGoal;

    /**
     * 研判意见
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String judgment;

    /**
     * 创建者ID
     */
    private Long creatorId;

    /**
     * 创建者账号
     */
    private String creatorName;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date updateTime;


    public GangGroupInfo(GangGroupInfoVO baseInfo) {
        this.groupName = baseInfo.buildNameStr();
        this.groupPicture = baseInfo.buildPictureStr();
        this.activeRegion = baseInfo.buildActiveRegionStr();
        this.groupPeopleCount = baseInfo.getGroupPeopleCount();
        this.degreeOfDanger = baseInfo.getDegreeOfDanger();
        this.tags = baseInfo.buildTagsStr();
        this.groupCreator = baseInfo.getGroupCreator();
        this.groupChief = baseInfo.getGroupChief();
        this.groupCreateTime = baseInfo.getGroupCreateTime();
        this.groupHeadquarters = baseInfo.getGroupHeadquarters();
        this.groupFaith = baseInfo.getGroupFaith();
        this.groupSocial = baseInfo.buildGroupSocialJSONStr();
        this.groupBrief = baseInfo.getGroupBrief();
        this.groupGoal = baseInfo.getGroupGoal();
        this.judgment = baseInfo.getJudgment();
    }

    public List<String> buildGroupNameList() {
        if (StringUtils.isNotBlank(this.groupName)) {
            return List.of(StringUtils.split(this.groupName, StringPool.COMMA));
        }
        return Collections.emptyList();
    }

    public List<String> buildGroupPictureList() {
        if (StringUtils.isNotBlank(this.groupPicture)) {
            return List.of(StringUtils.split(this.groupPicture, StringPool.COMMA));
        }
        return Collections.emptyList();
    }

    public List<String> buildActiveRegionList() {
        if (StringUtils.isNotBlank(this.activeRegion)) {
            return List.of(StringUtils.split(this.activeRegion, StringPool.COMMA));
        }
        return Collections.emptyList();
    }

    public List<String> buildTagsList() {
        if (StringUtils.isNotBlank(this.tags)) {
            return List.of(StringUtils.split(this.tags, StringPool.COMMA));
        }
        return Collections.emptyList();
    }

    public List<GangGroupInfoVO.GroupSocial> buildGroupSocialList() {
        if (StringUtils.isNotBlank(this.groupSocial)) {
            return JSONArray.parseArray(this.groupSocial, GangGroupInfoVO.GroupSocial.class);
        }
        return Collections.emptyList();
    }

    public String buildGroupNameFirst() {
        if (StringUtils.isNotBlank(this.groupName)) {
            String[] split = this.groupName.split(StringPool.COMMA);
            if (split.length > 0){
                return split[0];
            }
        }
        return null;
    }

    public String buildGroupPictureFirst() {
        if (StringUtils.isNotBlank(this.groupPicture)) {
            String[] split = this.groupPicture.split(StringPool.COMMA);
            if (split.length>0){
                return split[0];
            }
        }
        return null;
    }

    public String buildInfoFirst() {
        if (StringUtils.isNotBlank(this.judgment)) {
            return judgment;
        }
        if (StringUtils.isNotBlank(this.groupBrief)) {
            return groupBrief;
        }
        if (StringUtils.isNotBlank(this.groupGoal)) {
            return groupGoal;
        }
        return null;
    }

    public String buildActiveRegionFirst() {
        if (StringUtils.isNotBlank(this.activeRegion)) {
            String[] split = this.activeRegion.split(StringPool.COMMA);
            if (split.length>0){
                return split[0];
            }
        }
        return null;
    }
}
